package com.cjl.common.dtos;

import com.cjl.common.enums.HttpEnums;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author cjl
 * @version v1.0
 * @description TODO
 * @createTime 2023/2/7 17:30
 */

@Data
@ApiModel(value = "ResponseResult", description = "通用的http结果状态类")
public class ResponseResult<T> {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("状态结果消息")
    private String message;

    @ApiModelProperty("数据")
    private T data;

    public ResponseResult() {
    }

    public ResponseResult(Integer code) {
        this.code = code;
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult<?> ok() {
        this.code = HttpEnums.SUCCESS.getCode();
        this.message = HttpEnums.SUCCESS.getMessage();
        this.data = null;
        return this;
    }

    public ResponseResult<?> ok(HttpEnums httpEnums) {
        this.code = httpEnums.getCode();
        this.message = httpEnums.getMessage();
        this.data = null;
        return this;
    }

    public ResponseResult<?> ok(T data) {
        this.code = HttpEnums.SUCCESS.getCode();
        this.message = HttpEnums.SUCCESS.getMessage();
        this.data = data;
        return this;
    }

    public ResponseResult<?> ok(HttpEnums httpEnums, String message) {
        this.code = httpEnums.getCode();
        this.message = message;
        this.data = null;
        return this;
    }

    public ResponseResult<?> ok(HttpEnums httpEnums, T data) {
        this.code = httpEnums.getCode();
        this.message = httpEnums.getMessage();
        this.data = data;
        return this;
    }

    public ResponseResult<?> ok(HttpEnums httpEnums, String message, T data) {
        this.code = httpEnums.getCode();
        this.message = message;
        this.data = data;
        return this;
    }

    public static ResponseResult okResult() {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok();
    }

    public static ResponseResult okResult(HttpEnums httpEnums) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums);
    }

    public static ResponseResult okResult(HttpEnums httpEnums, String message) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, message);
    }

    public static ResponseResult okResult(String message, Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(HttpEnums.SUCCESS, message, data);
    }

    public static ResponseResult okResult(HttpEnums httpEnums, Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, data);
    }

    public static ResponseResult okResult(Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(data);
    }


    public static ResponseResult okResult(HttpEnums httpEnums, String message, Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, message, data);
    }


    public static ResponseResult errorResult(HttpEnums httpEnums) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums);
    }

    public static ResponseResult errorResult(HttpEnums httpEnums, String message) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, message);
    }

    public static ResponseResult errorResult(HttpEnums httpEnums, Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, data);
    }


    public static ResponseResult errorResult(HttpEnums httpEnums, String message, Object data) {
        ResponseResult responseResult = new ResponseResult();
        return responseResult.ok(httpEnums, message, data);
    }
}
